<template>
  <div class="report-form-container">
    <div class="header">
      <h1>错误反馈服务v1.0.0</h1>
    </div>
    <el-form :model="form" ref="reportForm" label-width="120px" class="report-form">
      <el-form-item label="* 选择上报信息" prop="class">
        <el-select v-model="form.class" placeholder="请选择信息">
          <el-option label="姓名" value="1"></el-option>
          <el-option label="班级" value="2"></el-option>
          <!-- 更多班级选项 -->
        </el-select>
      </el-form-item>
      <el-form-item label="* 修改为" prop="name">
        <el-input type="text"></el-input>
      </el-form-item>
      <el-form-item label="* 错误原因" prop="reason">
        <el-input
          type="textarea"
          placeholder="请输入错误原因"
          :rows="3">
        </el-input>
      </el-form-item>

      <!--上传组件-->
      <span>* 上传学生证照片</span>
      <br>
      <el-upload
        class="avatar-uploader"
        action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
        :show-file-list="false"
        :on-success="handleAvatarSuccess"
        :before-upload="beforeAvatarUpload"
      >
        <img v-if="imageUrl" :src="imageUrl" class="avatar" />
        <el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
      </el-upload>
      <br>
      <el-form-item>
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { ElForm, ElFormItem, ElInput, ElSelect, ElOption, ElRadioGroup, ElRadio, ElButton ,  } from 'element-plus';
import { Plus } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'

const form = ref({
  name: '',
  class: '',
  gender: 1, // 默认性别为男
});

const submitForm = () => {
  console.log('Form submitted:', form.value);
  // 这里添加提交表单的逻辑
};

const resetForm = () => {
  form.value = {
    name: '',
    class: '',
    gender: 1, // 重置性别为默认
  };
  const reportForm = ref(null);
  if (reportForm.value) {
    
  }
};

import type { UploadProps } from 'element-plus'

const imageUrl = ref('')

const handleAvatarSuccess: UploadProps['onSuccess'] = (
  response,
  uploadFile
) => {
  imageUrl.value = URL.createObjectURL(uploadFile.raw!)
}

const beforeAvatarUpload: UploadProps['beforeUpload'] = (rawFile) => {
  if (rawFile.type !== 'image/jpeg') {
    ElMessage.error('Avatar picture must be JPG format!')
    return false
  } else if (rawFile.size / 1024 / 1024 > 2) {
    ElMessage.error('Avatar picture size can not exceed 2MB!')
    return false
  }
  return true
}
</script>

<style scoped>
.report-form-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: white;
  padding: 30px;
  min-height: 100vh;
}

.header {
  width: 100%;
  text-align: center;
  padding: 20px 0;
}

.title {
  font-size: 2.5em;
  color: #333333;
  font-weight: bold;
  text-transform: uppercase;
  border-bottom: 4px solid #409eff;
  margin-bottom: 30px;
}

.report-form {
  width: 100%;
  max-width: 800px;
  background: #ffffff;
  border-radius: 10px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
  padding: 40px;
  box-sizing: border-box;
}

.el-form-item {
  margin-bottom: 20px;
}

.el-form-item__label {
  font-weight: 600;
  color: #555555;
}

.el-input__inner,
.el-select .el-input__inner {
  border-radius: 6px;
  border: 1px solid #c0c4cc;
}

.el-input__inner:focus,
.el-select .el-input__inner:focus {
  border-color: #409eff;
}

.el-button {
  border-radius: 25px;
  background: linear-gradient(90deg, #67b2e8 0%, #409eff 100%);
  color: white;
  transition: all 0.3s ease;
  padding: 10px 20px;
  font-weight: 600;
}

.el-button:hover {
  background: linear-gradient(90deg, #409eff 0%, #67b2e8 100%);
}

@media (max-width: 768px) {
  .report-form {
    padding: 20px;
  }

  .title {
    font-size: 2em;
  }
}

.avatar-uploader .avatar {
  width: 160px;
  height: 160px;
  display: block;
}
.avatar-uploader .el-upload {
  border: 1px dashed var(--el-border-color);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload:hover {
  border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 160px;
  height: 160px;
  border: #bac2cd 1px dashed;
  text-align: center;
  border-radius: 10px;
}
</style>